home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / PACKET / TFLINK10 / TFLNKBIN / TFTERM < prev   
Text File  |  1996-11-04  |  2KB  |  76 lines

  1. #!/bin/sh
  2. #
  3. # tfterm - simple terminal mode for testing TFLINK
  4. #
  5. # Tfterm is a UNIX (Linux) shell program that provides a simple terminal
  6. # with which to test TFLINK.  It first sets the serial port up to the
  7. # default settings for TFLINK - 9600 baud, 8 bits, no parity, 1 stop
  8. # bit, and "raw" data transfer with no echo.
  9. #
  10. # Next, it sets up the controlling TTY to be mostly raw, but with the
  11. # Ctrl-C character set up as the interrupt key.  Once done, it runs two
  12. # programs: a background cat(C) to read data from the serial line and
  13. # display it, and a foreground cat(C) to transfer characters from the
  14. # keyboard to the serial port.  The UNIX cu command is in fact capable
  15. # of most of this.
  16. #
  17. # To exit, enter ^C.  Terminal settings will be restored on normal exit.
  18. #
  19.  
  20. # definitions
  21. ME=`basename $0`
  22. USAGE="Usage: $ME [ -p device ] [ -b baudrate ]"
  23.  
  24. # check usage
  25. device="/dev/ttyS1"
  26. baudrate="9600"
  27. while getopts ":p:b:" arg; do
  28.     case "$arg" in
  29.     'p')    device="$OPTARG"
  30.         if [ ! -c $device ]; then
  31.             echo "$ME: $device device file not found" >&2
  32.             exit 1
  33.         fi ;;
  34.     'b')    baudrate="$OPTARG"
  35.         case "$baudrate" in
  36.         '110'|'300'|'600'|'1200'|'2400'|'4800'|'9600'|'19200') ;;
  37.         *)    echo "$ME: unrecognised baud rate $baudrate" >&2
  38.             exit 1 ;;
  39.         esac ;;
  40.     esac
  41. done
  42. shift `expr $OPTIND - 1`
  43. if [ $# -ne 0 ]; then
  44.     echo "$USAGE" >&2
  45.     exit 1
  46. fi
  47.  
  48. # set up the "TNC" serial line settings
  49. echo "TFTERM test TNC terminal program"
  50. echo "-- setting up terminal line $device, speed $baudrate baud"
  51. stty 1:0:8bd:0:0:0:0:0:0:0:1:0:0:0:0:0:0:0:0:0:0:0:0 <$device
  52. stty $baudrate <$device
  53.  
  54. # save current terminal line settings
  55. save_stty="`stty -g`"
  56.  
  57. # set raw terminal, but allow ~ as an interrupt keyA
  58. echo "-- setting up local terminal line"
  59. stty raw -echo isig intr ^C
  60.  
  61. # start echo (background) and copy (foreground) processes
  62. echo -e "-- connected, press ^C to exit\n"; sleep 1
  63. trap "" 1 2 3 15
  64. cat <$device &
  65. cat >$device
  66.  
  67. # get here when ^C quit entered - stop echoing
  68. kill -9 $!; sleep 1
  69.  
  70. # restore saved terminal line settings
  71. stty $save_stty
  72. echo -e "\n-- original terminal settings restored"
  73.  
  74. # all done
  75. exit 0
  76.